package Eyjafjalla.helper;

import Eyjafjalla.card.attack.*;
import Eyjafjalla.card.dolly.*;
import Eyjafjalla.card.power.*;
import Eyjafjalla.card.skill.*;
import Eyjafjalla.card.status.Cloud_Eyjafjalla;
import Eyjafjalla.card.status.Sunday_Eyjafjalla;
import Eyjafjalla.card.status.UnknownCloud_Eyjafjalla;
import Eyjafjalla.dungeons.TheSiesta;
import Eyjafjalla.event.ALetter;
import Eyjafjalla.modcore.ColorEnum;
import Eyjafjalla.modcore.EyjafjallaTag;
import Eyjafjalla.monster.*;
import Eyjafjalla.patch.PompeiiPatch;
import Eyjafjalla.relic.*;
import basemod.BaseMod;
import basemod.eventUtil.AddEventParams;
import basemod.eventUtil.EventUtils;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.core.Settings;
import com.megacrit.cardcrawl.dungeons.Exordium;
import com.megacrit.cardcrawl.dungeons.TheBeyond;
import com.megacrit.cardcrawl.dungeons.TheCity;
import com.megacrit.cardcrawl.localization.UIStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import com.megacrit.cardcrawl.monsters.MonsterGroup;
import com.megacrit.cardcrawl.monsters.MonsterInfo;
import com.megacrit.cardcrawl.relics.AbstractRelic;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringHelper {

    public static String CLOUD_ENERGY = "eyjafjalla:CloudEnergy";
    public static String CLOUD_OPERATION = "eyjafjalla:CloudOperation";
    public static String PROJECT = "eyjafjalla:Project";
    public static String SPECIAL_DESCRIPTION = "eyjafjalla:SpecialDescription";
    public static String DOLLY = "eyjafjalla:Dolly";
    public static String MELODY = "eyjafjalla:Melody";
    public static String CONFIG = "eyjafjalla:Config";
    public static String MELODY_WORD = "eyjafjalla:MelodyWord";
    public static String CAMPFIRE_OPERATION = "eyjafjalla:CampfireOperation";
    public static String SKIN_SELECT = "eyjafjalla:SkinSelect";

    public static final UIStrings projectStrings = CardCrawlGame.languagePack.getUIString(PROJECT);

    public static ArrayList<String> startDeck = new ArrayList<>();
    public static ArrayList<String> startRelic = new ArrayList<>();

    public static ArrayList<AbstractRelic> getRelicsToAdd(boolean onlyEyjafjalla){
        ArrayList<AbstractRelic> list = new ArrayList<>();

        if(onlyEyjafjalla){
            //STARTER
            list.add(new CloudInBottle());

            //COMMON
            list.add(new WarmFire());
            list.add(new DreamModel());
            list.add(new TreasureMap());
            list.add(new BellOfShepherd());
            list.add(new RainbowUrn());

            //UNCOMMON
            list.add(new UnknownMotherGoose());
            list.add(new GodRoll());
            list.add(new DrawPen());
            list.add(new StrangeFlute());

            //RARE
            list.add(new ShallowSong());
            list.add(new WitchAddax());

            //BOSS
            list.add(new CloudInPacket());
        }
        else {

            //COMMON
            list.add(new NightInForest());

            //UNCOMMON
            list.add(new ResplendentTear());

            //RARE
            list.add(new VoidBird());
            list.add(new GlassBird());

            //SPECIAL
            list.add(new VolcanoMask());
            list.add(new ShadowOfPompeii());
            list.add(new VolcanoBoom());
        }

        return list;
    }

    public static ArrayList<AbstractCard> getCardsToAdd(){
        ArrayList<AbstractCard> list = new ArrayList<>();

        //BASIC 4
        list.add(new Strike_Eyjafjalla());
        list.add(new Defend_Eyjafjalla());
        list.add(new BurnGround_Eyjafjalla());
        list.add(new FloorCloud_Eyjafjalla());

        //COMMON 19
        list.add(new IntoDream_Eyjafjalla());
        list.add(new ResonanceDefend_Eyjafjalla());
        list.add(new CloudCrack_Eyjafjalla());
        list.add(new HeartScar_Eyjafjalla());
        list.add(new Sunshine_Eyjafjalla());
        list.add(new ResearchOnNature_Eyjafjalla());
        list.add(new ThunderCloud_Eyjafjalla());
        list.add(new MissSound_Eyjafjalla());
        list.add(new SevenColor_Eyjafjalla());
        list.add(new RiseUp_Eyjafjalla());
        list.add(new UrgentPresto_Eyjafjalla());
        list.add(new HeartFeel_Eyjafjalla());
        list.add(new Chorus_Eyjafjalla());
        list.add(new InstantFireworks_Eyjafjalla());
        list.add(new FlutteringBreeze_Eyjafjalla());
        list.add(new FlameSurround_Eyjafjalla());
        list.add(new FlameMountain_Eyjafjalla());
        list.add(new DreamCradle_Eyjafjalla());
        list.add(new Fairy_Eyjafjalla());

        //UNCOMMON 36
        list.add(new Duetto_Eyjafjalla());
        list.add(new Morning_Eyjafjalla());
        list.add(new Afterglow_Eyjafjalla());
        list.add(new PracticalJoke_Eyjafjalla());
        list.add(new SilentWet_Eyjafjalla());
        list.add(new Ignition_Eyjafjalla());
        list.add(new ClearDream_Eyjafjalla());
        list.add(new CloudSilk_Eyjafjalla());
        list.add(new DenseMist_Eyjafjalla());
        list.add(new FireHeart_Eyjafjalla());
        list.add(new SayToSun_Eyjafjalla());
        list.add(new SilentSound_Eyjafjalla());
        list.add(new LiveStone_Eyjafjalla());
        list.add(new InSunset_Eyjafjalla());
        list.add(new SpurtOut_Eyjafjalla());
        list.add(new TranceDream_Eyjafjalla());
        list.add(new BetweenUs_Eyjafjalla());
        list.add(new Dreiton_Eyjafjalla());
        list.add(new PrepareBeforeCamp_Eyjafjalla());
        list.add(new CloudyBarrier_Eyjafjalla());
        list.add(new Push_Eyjafjalla());
        list.add(new HeartInCandy_Eyjafjalla());
        list.add(new Sailing_Eyjafjalla());
        list.add(new TheEnd_Eyjafjalla());
        list.add(new WaveFlower_Eyjafjalla());
        list.add(new FlameBurst_Eyjafjalla());
        list.add(new CloudMelody_Eyjafjalla());
        list.add(new Darkside_Eyjafjalla());
        list.add(new TreeAngle_Eyjafjalla());
        list.add(new VolcanicHealing_Eyjafjalla());
        list.add(new HappinessAria_Eyjafjalla());
        list.add(new SadnessRecitative_Eyjafjalla());
        list.add(new CloudCake_Eyjafjalla());
        list.add(new FollowHeart_Eyjafjalla());
        list.add(new LittleFeelings_Eyjafjalla());
        list.add(new TheLovedOne_Eyjafjalla());

        //RARE 15
        list.add(new Volcano_Eyjafjalla());
        list.add(new Inherit_Eyjafjalla());
        list.add(new SoLongAdele_Eyjafjalla());
        list.add(new Shuttle_Eyjafjalla());
        list.add(new PulseOfTerra_Eyjafjalla());
        list.add(new PinkOcean_Eyjafjalla());
        list.add(new FireOfLove_Eyjafjalla());
        list.add(new LetRainGo_Eyjafjalla());
        list.add(new AnswerInWind_Eyjafjalla());
        list.add(new TimeOfLove_Eyjafjalla());
        list.add(new GoldAndRoses_Eyjafjalla());
        list.add(new VolcanoEcho_Eyjafjalla());
        list.add(new SongOfLove_Eyjafjalla());
        list.add(new DancingLava_Eyjafjalla());
        list.add(new BlazePrelude_Eyjafjalla());

        //SPECIAL 11
        list.add(new ReIgnition_Eyjafjalla());
        list.add(new Marshmallow_Eyjafjalla());
        list.add(new Cloud_Eyjafjalla());
        list.add(new UnknownCloud_Eyjafjalla());
        list.add(new Sunday_Eyjafjalla());
        list.add(new VolcanoStone_Eyjafjalla());
        list.add(new Songs_Eyjafjalla());
        list.add(new SongMary_Eyjafjalla());
        list.add(new SongFarmer_Eyjafjalla());
        list.add(new SongBoat_Eyjafjalla());
        list.add(new DollyInvitation_Eyjafjalla());

        return list;
    }

    public static ArrayList<AbstractCard> getDollyCardsToAdd(){
        ArrayList<AbstractCard> list = new ArrayList<>();
        //DOLLY

        //COMMON
        list.add(new TQB_Eyjafjalla());
        list.add(new CPS_Eyjafjalla());
        list.add(new LLH_Eyjafjalla());
        list.add(new FKY_Eyjafjalla());
        list.add(new FXZ_Eyjafjalla());

        //UNCOMMON
        list.add(new LTTQB_Eyjafjalla());
        list.add(new JMCPS_Eyjafjalla());
        list.add(new NSLLH_Eyjafjalla());
        list.add(new MTFKY_Eyjafjalla());
        list.add(new LJFXZ_Eyjafjalla());
        list.add(new DGZ_Eyjafjalla());
        list.add(new XSS_Eyjafjalla());

        //RARE
        list.add(new DGDGZ_Eyjafjalla());
        list.add(new CXXSS_Eyjafjalla());

        //SP
        list.add(new HPY_Eyjafjalla());


        return list;
    }

    public static void initializeMonsters(){
        UIStrings ui = CardCrawlGame.languagePack.getUIString("eyjafjalla:MonsterNames");
        String[] names = ui.TEXT;
        //NORMAL
        //01 N_E_TQB
        BaseMod.addMonster("N_E_TQB",names[0],()->{
            return new MonsterGroup(new AbstractMonster[]{
               new TQB(0,0,false)
            });
        });
        BaseMod.addMonsterEncounter(TheSiesta.ID,new MonsterInfo("N_E_TQB",1F));
        //02 N_E_CPS_CPS
        BaseMod.addMonster("N_E_CPS_CPS",names[2],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new CPS(-200F,0F),
                    new CPS(100F,0F)
            });
        });
        BaseMod.addMonsterEncounter(TheSiesta.ID,new MonsterInfo("N_E_CPS_CPS",1F));
        //STRONG NORMAL
        //01 H_E_TQB_LTTQB
        BaseMod.addMonster("H_E_TQB_LTTQB",names[1],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new TQB(-200F,0F,false),
                    new LTTQB(100F,0F)
            });
        });
        BaseMod.addStrongMonsterEncounter(TheSiesta.ID,new MonsterInfo("H_E_TQB_LTTQB",1F));
        //02 H_E_CPS_LTTQB
        BaseMod.addMonster("H_E_CPS_LTTQB",names[3],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new CPS(-200F,0F),
                    new LTTQB(100F,0F)
            });
        });
        BaseMod.addStrongMonsterEncounter(TheSiesta.ID,new MonsterInfo("H_E_CPS_LTTQB",1F));

        //ELITE
        //01 E_E_JMCPS_MTFKY
        BaseMod.addMonster("E_E_JMCPS_MTFKY",names[4],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new JMCPS(-100F,0F),
                    new MTFKY(200F,0F)
            });
        });
        BaseMod.addEliteEncounter(TheSiesta.ID,new MonsterInfo("E_E_JMCPS_MTFKY",3F));
        //02 E_E_CXXSS_4
        BaseMod.addMonster("E_E_CXXSS_4",names[6],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new CXXSS(-600F,0F,true),
                    new CXXSS(-350F,10F,false),
                    new CXXSS(-100F,0F,true),
                    new CXXSS(150F,10F,false)
            });
        });
        BaseMod.addEliteEncounter(TheSiesta.ID,new MonsterInfo("E_E_CXXSS_4",3F));
        //03 E_E_DGDGZ
        BaseMod.addMonster("E_E_DGDGZ",names[7],()->{
            return new MonsterGroup(new AbstractMonster[]{
                    new DGDGZ(100F,0F)
            });
        });
        BaseMod.addEliteEncounter(TheSiesta.ID,new MonsterInfo("E_E_DGDGZ",3F));
        //BOSS
        BaseMod.addMonster(Dolly.ID,names[5],()->{
            return new MonsterGroup(new AbstractMonster[]{
               new Dolly(0,0)
            });
        });
        BaseMod.addBoss(TheSiesta.ID,Dolly.ID,Dolly.ICON,Dolly.ICON_O);
    }

    public static void initializeEvents() {
        BaseMod.addEvent((new AddEventParams.Builder(ALetter.ID, ALetter.class))
                .eventType(EventUtils.EventType.ONE_TIME)
                .dungeonID(Exordium.ID)
                .dungeonID(TheCity.ID)
                .dungeonID(TheBeyond.ID)
                .endsWithRewardsUI(false)
                .spawnCondition(() -> {
                    return !PompeiiPatch.enterEvent;
                }).create());
    }

    public static void addProject(AbstractCard c) {
        if (!c.hasTag(EyjafjallaTag.PROJECT_EYJAFJALLA)) {
            c.tags.add(EyjafjallaTag.PROJECT_EYJAFJALLA);
            c.name = c.name + projectStrings.TEXT[0];
            c.exhaust = true;
            c.isEthereal = true;
            c.exhaustOnUseOnce = true;
        }
    }

    public static String getRelicIMGPATH(String ID,boolean outline){
        //replace
        ID = ID.replace("eyjafjalla:","");
        if(outline){
            return "EyjafjallaResources/img/relic/outline/"+ID+".png";
        }
        return "EyjafjallaResources/img/relic/"+ID+".png";
    }

    public static String getCardIMGPatchTemp(AbstractCard.CardType type){
        String path = "";
        switch (type){
            case ATTACK : {
                path = "EyjafjallaResources/img/card/temp/Attack.png";
                break;
            }
            case SKILL : {
                path = "EyjafjallaResources/img/card/temp/Skill.png";
                break;
            }
            case POWER : {
                path = "EyjafjallaResources/img/card/temp/Power.png";
                break;
            }
            case CURSE : {
                path = "EyjafjallaResources/img/card/temp/Other.png";
                break;
            }
            case STATUS :
                path = "EyjafjallaResources/img/card/temp/Other.png";
                break;
        }
        return path;
    }

    public static String getCardIMGPatch(String ID, AbstractCard.CardType type){
        switch (type) {
            case ATTACK: {
                ID += "_attack";
                break;
            }
            case CURSE:
            case STATUS:
            case SKILL: {
                ID += "_skill";
                break;
            }
            case POWER: {
                ID += "_power";
                break;
            }
        }
        return "EyjafjallaResources/img/card/" + ID + ".png";
    }

    public static String getCardIMGPatch(String ID, AbstractCard.CardType type, AbstractCard.CardColor color){
        switch (type) {
            case ATTACK: {
                ID += "_attack";
                break;
            }
            case CURSE:
            case STATUS:
            case SKILL: {
                ID += "_skill";
                break;
            }
            case POWER: {
                ID += "_power";
                break;
            }
        }
        return "EyjafjallaResources/img/card/" +(color.equals(ColorEnum.Eyjafjalla_Dolly_COLOR)?"dolly/":"")+ ID + ".png";
    }

    public static String colorString(String input, String colorValue) {
        StringBuilder retVal = new StringBuilder();
        Scanner s = new Scanner(input);

        while(s.hasNext()) {
            retVal.append("[").append(colorValue).append("]").append(s.next());
            retVal.append("[] ");
        }

        s.close();
        return retVal.toString().trim();
    }

    static {
        for(int i =0;i<5;i++){
            startDeck.add(Strike_Eyjafjalla.ID);
        }
        for (int i =0;i<5;i++){
            startDeck.add(Defend_Eyjafjalla.ID);
        }
        startDeck.add(BurnGround_Eyjafjalla.ID);
        startDeck.add(FloorCloud_Eyjafjalla.ID);

        startRelic.add(CloudInBottle.ID);
    }
}
